{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-31T08:32:14.278074Z",
     "start_time": "2025-10-31T08:32:14.272879Z"
    }
   },
   "source": [
    "from typing import Annotated\n",
    "\n",
    "from typing_extensions import TypedDict\n",
    "\n",
    "from langgraph.graph import StateGraph\n",
    "from langgraph.graph.message import add_messages\n",
    "\n",
    "\n",
    "class AgentState(TypedDict):\n",
    "    # Messages have the type \"list\". The `add_messages` function\n",
    "    # in the annotation defines how this state key should be updated\n",
    "    # (in this case, it appends messages to the list, rather than overwriting them)\n",
    "    messages: Annotated[list, add_messages]\n",
    "\n",
    "graph_builder = StateGraph(AgentState)"
   ],
   "outputs": [],
   "execution_count": 7
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T08:32:16.715207Z",
     "start_time": "2025-10-31T08:32:14.288203Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from langchain_ollama import OllamaLLM\n",
    "\n",
    "ollama = OllamaLLM(model=\"qwen3:8b\")\n",
    "\n",
    "ollama"
   ],
   "id": "5367e2d00a196995",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "OllamaLLM(model='qwen3:8b')"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 8
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T08:32:16.732788Z",
     "start_time": "2025-10-31T08:32:16.726200Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def chatbot(state: AgentState):\n",
    "    return {\"messages\": [ollama.invoke(state[\"messages\"])]}\n",
    "\n",
    "\n",
    "# The first argument is the unique node name\n",
    "# The second argument is the function or object that will be called whenever\n",
    "# the node is used.\n",
    "graph_builder.add_node(\"chatbot\", chatbot)"
   ],
   "id": "52539182b32502c",
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<langgraph.graph.state.StateGraph at 0x1d2a495ba70>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 9
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T08:32:16.751887Z",
     "start_time": "2025-10-31T08:32:16.744786Z"
    }
   },
   "cell_type": "code",
   "source": [
    "graph_builder.set_entry_point(\"chatbot\")\n",
    "graph_builder.set_finish_point(\"chatbot\")\n",
    "\n",
    "graph = graph_builder.compile()\n",
    "graph.get_graph().print_ascii()"
   ],
   "id": "49d3c55cfead7509",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "+-----------+  \r\n",
      "| __start__ |  \r\n",
      "+-----------+  \r\n",
      "      *        \r\n",
      "      *        \r\n",
      "      *        \r\n",
      " +---------+   \r\n",
      " | chatbot |   \r\n",
      " +---------+   \r\n",
      "      *        \r\n",
      "      *        \r\n",
      "      *        \r\n",
      " +---------+   \r\n",
      " | __end__ |   \r\n",
      " +---------+   \n"
     ]
    }
   ],
   "execution_count": 10
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T08:32:17.927559Z",
     "start_time": "2025-10-31T08:32:16.766543Z"
    }
   },
   "cell_type": "code",
   "source": [
    "from IPython.display import Image, display\n",
    "\n",
    "display(Image(graph.get_graph().draw_mermaid_png(max_retries=5)))"
   ],
   "id": "7f3fe229a5ed0f10",
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAGoAAADqCAIAAADF80cYAAAQAElEQVR4nOydCVwTR9/HZzcHhAQIcsglAqIC6gMqKj4qtOLVPvp4lD61Hm+r7Vvl8W7to1bbp2it7WNtfV5ra21rtVa01bZC1SpWqxaxXuAB3lwighGQHCSQZHff2SSEqEl2wya6kv36+cTszOxs9scc/52ZnT+fIAjA0Vb4gIMBnHyM4ORjBCcfIzj5GMHJxwim8pUVa24UKJVynVqhx/QAWFhBCAqPCIAj5BfcEMIDBAYASgYaEwCEDDEcoy2nAQQxpEfg2Yg5kMwZ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Gg4HskG748qRmwGhwvR5YfRPcXiNS+Fhef7eu15SUVRSMGgvVF+pr69UdOou/vsMx26qjQvUNmeWqxR6ib8osveTLeLty/XyGiUcxv77a+HBUQ7P6rR9fd/1QvUf2bJGuZ7HRz28+N6BEp+OYk8J2yt1sxrT1DfLZSqNqhnTYkIPJD5ZSrOjeBjGr8XgYN/mmqoSjbYJN2aFwCFa4qHVuXYxL0W1fxL9QDuXgmY8nMEQCNGAMGHyM/7BUR6AAc5/q0ijIicyLC9B3iMKx20fvBCBQqVbk5iAI1FwnMhyUTKw5jnKnGGr86iH/EqhhrW/ZnhAJOIBp3qvYLurJ5bTDu2PRwknHyM4+RjByccITj5GcPIx4v8BAAD//2pcLOUAAAAGSURBVAMAFowuycKA8vEAAAAASUVORK5CYII=",
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "execution_count": 11
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-10-31T08:33:20.619274Z",
     "start_time": "2025-10-31T08:32:17.939072Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def stream_graph_updates(user_input: str):\n",
    "    for event in graph.stream({\"messages\": [{\"role\": \"user\", \"content\": user_input}]}):\n",
    "        for value in event.values():\n",
    "            # 检查消息是字符串还是消息对象\n",
    "            last_message = value[\"messages\"][-1]\n",
    "            if hasattr(last_message, 'content'):\n",
    "                # 如果是消息对象，直接访问content属性\n",
    "                print(\"Assistant:\", last_message.content)\n",
    "            else:\n",
    "                # 如果是字符串，直接打印\n",
    "                print(\"Assistant:\", last_message)\n",
    "\n",
    "\n",
    "while True:\n",
    "    try:\n",
    "        user_input = input(\"User: \")\n",
    "        if user_input.lower() in [\"quit\", \"exit\", \"q\"]:\n",
    "            print(\"Goodbye!\")\n",
    "            break\n",
    "        stream_graph_updates(user_input)\n",
    "    except:\n",
    "        # fallback if input() is not available\n",
    "        user_input = \"What do you know about LangGraph? /nothink\"\n",
    "        print(\"User: \" + user_input)\n",
    "        stream_graph_updates(user_input)\n",
    "        break"
   ],
   "id": "3a4b6c9c99921739",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Assistant: <think>\n",
      "Okay, the user asked, \"who are you?\" I need to provide a clear and concise answer. Let me start by introducing myself as Qwen, developed by Alibaba Cloud. I should mention my capabilities like answering questions, creating content, and engaging in conversations. It's important to highlight my role as a large language model and my purpose to assist users. I should keep the response friendly and open-ended, inviting them to ask more questions. Let me make sure the tone is approachable and the information is accurate. Alright, that should cover it.\n",
      "</think>\n",
      "\n",
      "Hello! I am Qwen, a large language model developed by Alibaba Cloud. I am designed to assist with a wide range of tasks, such as answering questions, creating content, engaging in conversations, and providing information. My goal is to help users by offering useful and accurate responses. How can I assist you today? 😊\n",
      "Goodbye!\n"
     ]
    }
   ],
   "execution_count": 12
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
